package com.jstyle.jclife.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jstyle.jclife.R;
import com.jstyle.jclife.utils.ScreenUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/9/27.
 */

public class FileUpdateDialog extends JstyleDialog {
    @BindView(R.id.tv_find_new_version)
    TextView tvFindNewVersion;
    @BindView(R.id.tv_update_version)
    TextView tvUpdateVersion;
    @BindView(R.id.bt_update)
    Button btUpdate;
    @BindView(R.id.bt_update_cancel)
    Button btUpdateCancel;

    public FileUpdateDialog(@NonNull Context context) {
        super(context);

    }

    public FileUpdateDialog(@NonNull Context context, int themeResId, String version) {
        super(context, themeResId);
        init(context,themeResId,version);
    }
    private void init(Context context,int themeResId,String version) {
        initStyle(themeResId);
        initWidth(ScreenUtils.getScreenWidth(context));
        initGravity(Gravity.CENTER);
        if(!TextUtils.isEmpty(version))
        tvUpdateVersion.setText("V"+version);
    }


    @Override
    protected void setContentView() {
        setContentView(R.layout.dialog_whether_update);
    }

    @OnClick({R.id.bt_update, R.id.iv_fileupdate_off, R.id.bt_update_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_fileupdate_off:
                if(fileUpdateListener!=null)fileUpdateListener.laterUpdateFile();

                dismiss();
                break;
            case R.id.bt_update:
                if(fileUpdateListener!=null)fileUpdateListener.startUpdateFile();
                dismiss();
                break;
            case R.id.bt_update_cancel:
                if(fileUpdateListener!=null)fileUpdateListener.laterUpdateFile();

                dismiss();
                break;
        }
    }
    public FileUpdateListener fileUpdateListener;
    public void setFileUpdateListener(FileUpdateListener fileUpdateListener){
        this.fileUpdateListener=fileUpdateListener;
    }
    public interface FileUpdateListener{
        public void startUpdateFile();
        public void laterUpdateFile();
    }
}
